import time

import akshare as ak
import pandas as pd

date = time.strftime("%Y%m%d", time.localtime())

# 第一步 获取所有指数估值数据
# 指数估值 韭圈儿
# https://funddb.cn/site/index
srcData = ak.index_value_name_funddb()
srcData = srcData.sort_values(by='PE分位', ascending=True)
srcData.to_excel(f"指数估值-{date}.xlsx", index=False)

res = "./resource/指数列表.csv"
df = pd.read_csv(res)
rsList = []
for row in df.itertuples(index=False):
    code = getattr(row, '指数代码')
    d = srcData[srcData['指数代码'] == code]
    rsList.append(d)

rs = pd.concat(rsList, ignore_index=True)
rs.to_excel(f"指数估值-自选指数-{date}.xlsx", index=False)